package com.pillpoppers.pillbox.database;


import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class PillTable {

  // Database table
  public static final String TABLE_PILL = "pill";
  public static final String COLUMN_ID = "_id";
  public static final String COLUMN_TYPE = "type";
  public static final String COLUMN_NAME = "name";
  public static final String COLUMN_DESCRIPTION = "description";
  public static final String COLUMN_MAX_COUNT = "max_count";
  public static final String COLUMN_CURRENT_COUNT = "current_count";
  public static final String COLUMN_WARNINGS = "warnings";
  public static final String COLUMN_SIDE_EFFECTS = "side_effects";
  public static final String COLUMN_CONTACT = "contact";
  public static final String COLUMN_SCHEDULE = "schedule"; // Causing error removed for now

  // Database creation SQL statement
  private static final String DATABASE_CREATE = "create table " 
      + TABLE_PILL + "(" + COLUMN_ID + " integer primary key autoincrement, " 
      + COLUMN_TYPE + " text not null, " 
      + COLUMN_NAME + " text not null, " 
      + COLUMN_CURRENT_COUNT + " text not null, "
      + COLUMN_MAX_COUNT + " text not null, "
      + COLUMN_DESCRIPTION + " text not null, "
      + COLUMN_WARNINGS + " text not null, "
      + COLUMN_SIDE_EFFECTS + " text not null, "
      + COLUMN_CONTACT + " text not null,"
      + COLUMN_SCHEDULE + " text not null" 
      + ");";

  // Database on create
  public static void onCreate(SQLiteDatabase database) {
    database.execSQL(DATABASE_CREATE);
  }

  // Database on upgrade
  public static void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion)
  {
	  Log.w(PillTable.class.getName(), "Upgrading database from version "
        + oldVersion + " to " + newVersion
        + ", which will destroy all old data");
	  database.execSQL("DROP TABLE IF EXISTS " + TABLE_PILL);
	  
	  onCreate(database);
  }
}